package com.heer.gymnasium.module.order.beans;

import com.heer.gymnasium.constant.Type;
import com.heer.gymnasium.util.StringUtils;

import org.json.JSONException;
import org.json.JSONObject;

import java.sql.Struct;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by yan
 * on 2018/3/5
 */

public class OrderBean {
    private String orderId;
    private String stadiumName;
    private String info;
    private String orderType;
    private String totalCount;
    private String payMoney;
    private String total_money;
    private List detailList;
    private String num;//次卡数量
    private String account;//余额
    private CardDetail cardDetail;
    private MyOrderBean.DetailCoach detailCoach;


    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public String getStadiumName() {
        return stadiumName;
    }

    public void setStadiumName(String stadiumName) {
        this.stadiumName = stadiumName;
    }

    public String getInfo() {
        return info;
    }

    public void setInfo(String info) {
        this.info = info;
    }

    public String getOrderType() {
        return orderType;
    }

    public void setOrderType(String orderType) {
        this.orderType = orderType;
    }

    public String getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(String totalCount) {
        this.totalCount = totalCount;
    }

    public String getPayMoney() {
        return payMoney;
    }

    public void setPayMoney(String payMoney) {
        this.payMoney = payMoney;
    }

    public String getTotal_money() {
        return total_money;
    }

    public void setTotal_money(String total_money) {
        this.total_money = total_money;
    }

    public List getDetailList() {
        return detailList;
    }

    public void setDetailList(List detailList) {
        this.detailList = detailList;
    }

    public String getNum() {
        return num;
    }

    public void setNum(String num) {
        this.num = num;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public CardDetail getCardDetail() {
        return cardDetail;
    }

    public void setCardDetail(CardDetail cardDetail) {
        this.cardDetail = cardDetail;
    }

    public MyOrderBean.DetailCoach getDetailCoach() {
        return detailCoach;
    }

    public void setDetailCoach(MyOrderBean.DetailCoach detailCoach) {
        this.detailCoach = detailCoach;
    }

    public static class CardDetail {
        private String cardName;
        private String cardType;
        private String expire;
        private String count;
        private String price;
        private String cardId;

        public String getCardName() {
            return cardName;
        }

        public void setCardName(String cardName) {
            this.cardName = cardName;
        }

        public String getCardType() {
            return cardType;
        }

        public void setCardType(String cardType) {
            this.cardType = cardType;
        }

        public String getExpire() {
            return expire;
        }

        public void setExpire(String expire) {
            this.expire = expire;
        }

        public String getCount() {
            return count;
        }

        public void setCount(String count) {
            this.count = count;
        }

        public String getPrice() {
            return price;
        }

        public void setPrice(String price) {
            this.price = price;
        }

        public String getCardId() {
            return cardId;
        }

        public void setCardId(String cardId) {
            this.cardId = cardId;
        }
    }

    public static OrderBean dataChange(OrderInfoResponseBean responseBean, String orderType) {
        OrderBean orderBean = new OrderBean();
        orderBean.setOrderId(responseBean.getOrder_id());
        orderBean.setPayMoney(responseBean.getPay_money());
        orderBean.setTotal_money(responseBean.getTotal_money());
        orderBean.setAccount(responseBean.getAccount());

        orderBean.setOrderType(orderType);
        try {
            if (orderType.equals(Type.ORDER_ONE_STDIUM) || orderType.equals(Type.ORDER_MORE_STDIUM) || orderType.equals(Type.ORDER_YUE) || orderType.equals(Type.ORDER_FELLOW)) {
                List<MyOrderBean.DetialStadium> list = new ArrayList<>();
                for (int i = 0; i < responseBean.getDetail_list().size(); i++) {
                    JSONObject jsonObject = new JSONObject(responseBean.getDetail_list().get(i).getData());
                    String place = jsonObject.getString("place");
                    String stadium = jsonObject.getString("stadium");
                    JSONObject jsonObjectForPlace = new JSONObject(place);
                    JSONObject jsonObjectForStadium = new JSONObject(stadium);
                    orderBean.setStadiumName(jsonObjectForStadium.getString("name"));
                    MyOrderBean.DetialStadium detail = new MyOrderBean.DetialStadium();
                    detail.setPlaceName(jsonObjectForPlace.getString("place_name"));
                    detail.setPrice(jsonObjectForPlace.getString("place_name"));
                    detail.setPrice(jsonObjectForPlace.getString("price"));
                    detail.setDetailId(responseBean.getDetail_list().get(i).getDetail_id());
                    detail.setTime(StringUtils.getPhpDate(responseBean.getDetail_list().get(i).getStime()) + "-"
                            + StringUtils.getPhpDateFormat(responseBean.getDetail_list().get(i).getEtime(), new SimpleDateFormat("HH:mm")));
                    list.add(detail);
                }
                orderBean.setDetailList(list);
                orderBean.setInfo(responseBean.getIntr());
                orderBean.setTotalCount(list.size() + "");
            } else if (orderType.equals(Type.BUY_CARD_TYPE)) {
                JSONObject jsonObject = new JSONObject(responseBean.getDetail_list().get(0).getData());
                String stadium = jsonObject.getString("stadium");
                JSONObject jsonObjectForStadium = new JSONObject(stadium);
                orderBean.setStadiumName(jsonObjectForStadium.getString("name"));

                String card = jsonObject.getString("card");
                JSONObject jsonObjectForCard = new JSONObject(card);

                CardDetail detail = new CardDetail();
                detail.setCardName(jsonObjectForCard.getString("card_name"));
                detail.setPrice(jsonObjectForCard.getString("price"));
                detail.setCount(jsonObjectForCard.getString("num"));
                detail.setExpire(jsonObjectForCard.getString("expire"));
                detail.setCardId(responseBean.getDetail_list().get(0).getDetail_id());
                orderBean.setCardDetail(detail);

            } else if (orderType.equals(Type.RECHARGE_TYPE)) {
                JSONObject jsonObject = new JSONObject(responseBean.getDetail_list().get(0).getData());
                String stadium = jsonObject.getString("stadium");
                JSONObject jsonObjectForStadium = new JSONObject(stadium);
                orderBean.setStadiumName(jsonObjectForStadium.getString("name"));

            } else if (orderType.equals(Type.COACH_TYPE)) {
                JSONObject jsonObject = new JSONObject(responseBean.getDetail_list().get(0).getData());
                String stadium = jsonObject.getString("stadium");
                JSONObject jsonObjectForStadium = new JSONObject(stadium);
                orderBean.setStadiumName(jsonObjectForStadium.getString("name"));

                String coach = jsonObject.getString("coach");
                JSONObject jsonObjectForCoach = new JSONObject(coach);
                MyOrderBean.DetailCoach detail = new MyOrderBean.DetailCoach();
                detail.setCoachName(jsonObjectForCoach.getString("coach_name"));
                detail.setPrice(jsonObjectForCoach.getString("price"));
                orderBean.setDetailCoach(detail);
                orderBean.setNum(responseBean.getNum());
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return orderBean;
    }

}
